// component/pay-dialog/pay-dialog.js
const app = getApp();
const payHelper = require("../../utils/pay.js");
Component({
  options: {
    addGlobalClass: true
  },
  /**
   * 组件的属性列表
   */
  properties: {
    payAmount: Number,
    payOrderType: {
      type: Number,
      value: 0,
      default: 0
    },
    payOrderId: String,
    store: Object
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    hiddenDialog: function(e, payed) {
      console.log(payed)
      this.triggerEvent('hiddenDialog', {
        payed: payed
      })
    },
    //进行支付
    toPay: function(e) {
      let that = this;
      let orderId = that.data.payOrderId;
      let userId = app.globalData.userBean.consumerId;
      app.showLoading()
      payHelper.pay(orderId, userId).then(res => {
        setTimeout(function() {
          tt.hideLoading()
          that.hiddenDialog(null, true);
        }, 500)
      }).catch(msg => {
        tt.hideLoading()
        let message = typeof msg == "string" ? msg : msg.message;
        app.showToast(message);
      });
    },
  }
})